using UnityEngine;
using System.Collections;

public enum MouseMessageType
{
	LEFT_CLICK,
	AREA_SELECT,
	RIGHT_CLICK,
	MIDDLE_CLICK,
};

public class MouseMes : Message
{
	private MouseMessageType mType;
	public int UnitNum;
	public Vector2 mPos;
	//area select only
	private Vector2 mSize;
	
	public MouseMes(string buffer)
	{
		messageBuffer = buffer;
		unPack();
	}
	public MouseMes(MouseMessageType aType, Vector2 aPos, int playerNum){Set(aType, aPos, playerNum);}
	public MouseMes(MouseMessageType aType, Vector2 aPos, Vector2 aSize, int playerNum){Set(aType, aPos, aSize, playerNum);}
	
	public void Set(MouseMessageType aType, Vector2 aPos, int playerNum)
	{
		mType = aType;
		mPos = aPos;
		UnitNum = playerNum;
	}
	
	public void Set(MouseMessageType aType, Vector2 aPos, Vector2 aSize, int playerNum)
	{
		Set (aType, aPos, playerNum);
		mSize = aSize;
	}
	
	override public void pack()
	{
		//M#TYPE#POSX#POSY#SIZEX#SIZEY#
		messageBuffer = "M#" + mType.ToString("D") + "#" + mPos.x + "#" + mPos.y + "#" + mSize.x + "#" + mSize.y + "#" + UnitNum + "#\0";
	}
	public override void unPack ()
	{
		//M#TYPE#POSX#POSY#SIZEX#SIZEY#
		string[] mes = messageBuffer.Split('#');
		mType = (MouseMessageType)int.Parse(mes[0]);
		mPos.x = float.Parse(mes[1]);
		mPos.y = float.Parse(mes[2]);
		mSize.x = float.Parse(mes[3]);
		mSize.y = float.Parse(mes[4]);
		UnitNum = int.Parse(mes[5]);
	}
}
